<?php

    define("ABAVC_PHP_PATH","/usr/bin/php");
    define("ABAVC_FFMPEG_PATH","/usr/bin/ffmpeg");
    //define("ABAVC_FFMPEG_COMMANDLINE","%program% -y -i %input% -s 320x180 -r 30000/1001 -b 400k -bt 500k -vcodec libx264  -acodec aac -ac 2 -ar 44100 -ab 128k -strict -2 %output%;");
    define("ABAVC_FFMPEG_COMMANDLINE","%program% -y -i %input%   -vcodec libx264  -acodec aac -ac 2 -ar 44100 -ab 128k -strict -2 -f mp4 %output% ");

    function exponent_unhtmlentities( $str )
    {
        $trans = get_html_translation_table(HTML_ENTITIES);
        $trans['&apos;'] = '\'';
        $trans=array_flip($trans);

        $trans['&apos;'] = '\'';
        $trans['&#039;'] = '\'';
        return strtr($str, $trans);
    }
    
    /**
    * @param mixed $type : = 0 / 1 ; 0 for cases ; 1 for documents
    */
    function avc_sendmail($mail_to, $data, $type=0)
    {
        if (!is_array($mail_to))
            $mail_to=array($mail_to);
        
        // send mail
        $headers = array();
        $headers['From'] =  SMTP_FROMADDRESS ;
        $headers['Reply-to'] = SMTP_FROMADDRESS;
        $mail = new exponentMail();
        $mail->addHeaders($headers);
        $mail->addFrom(SMTP_FROMADDRESS, SITE_TITLE );
        
        $output = "";
        if ($type == 0) // cases
        {
            $output =" Hello, on ".date('l jS \of F Y h:i:s A')."<br><br>We get issue to convert FLV file to MP4 from CASES data. Here is dump of your data. Please double check. <br><br>";
            $output.=var_export($data,true);
        }
        else
        {
            $output =" Hello, on ".date('l jS \of F Y h:i:s A')."<br><br>We get issue to convert FLV file to MP4 from DOCUMENTS data. Here is dump of your data. Please double check. <br><br>";
            $output.=var_export($data,true);
        }
        
        $mail->addTo($mail_to);
        $mail->subject("iPhone Video Convert Report: Convertion failure for {$file_path}");
        $mail->addHTML($output);
        @$mail->send();

    }

    function ffmpeg_toIphone_Convert($file_path){

        if (substr($file_path,0,1) == "/")
            $file_path=substr($file_path, 1);

        $des = BASE.substr ($file_path,0, strlen($file_path)-3)."mp4";

        $file_path=BASE.$file_path;

        // build command
        $command = str_replace("%program%", ABAVC_FFMPEG_PATH , ABAVC_FFMPEG_COMMANDLINE);
        $command = str_replace("%input%", "\"{$file_path}\"" , $command);
        $command = str_replace("%output%", "\"{$des}\"" , $command);

        $command = escapeshellcmd ($command);
        $ret=exec($command, $ret2);

        // chmod
        chmod($des, 0775);

    }
?>
